<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<c:set value="<%=request.getContextPath()%>" var="ctx"></c:set>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>产码记录信息列表</title>
    <meta name="keywords" content="关键字">
    <meta name="description" content="描述">
     <link href="${ctx}/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${ctx}/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <!-- Data Tables -->
    <link href="${ctx}/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
    <link href="${ctx}/css/animate.css" rel="stylesheet">
    <link href="${ctx}/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="${ctx}/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
        <!-- 全局js -->
    <script src="${ctx}/js/jquery.min.js?v=2.1.4"></script>
    <script src="${ctx}/js/bootstrap.min.js?v=3.3.6"></script>
	<script src="${ctx}/js/jquery.validate.min.js?v=2.1.4"></script>
    <script src="${ctx}/js/plugins/jeditable/jquery.jeditable.js"></script>

    <!-- Data Tables -->
    <script src="${ctx}/js/plugins/dataTables/jquery.dataTables.js"></script>
    <script src="${ctx}/js/plugins/dataTables/dataTables.bootstrap.js"></script>
    <script src="${ctx}/js/plugins/layer/layer.min.js"></script>
    <!-- 自定义js -->
    <script src="${ctx}/js/content.js?v=1.0.0"></script>
    <script src="${ctx}/js/plugins/sweetalert/sweetalert.min.js"></script>
    <%-- <script src="${ctx}/js/areaList/areaList.js"></script> --%>
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox">
                    <div class="ibox-title">
                        <div class="row">
                           <div class="col-sm-10">
                                <h3>产码记录信息列表</h3>
                           </div>
                           <div class="col-sm-2">
                               
                            </div>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div id="progressBar" class="sk-spinner sk-spinner-wave" >
                            <div class="sk-rect1"></div>
                            <div class="sk-rect2"></div>
                            <div class="sk-rect3"></div>
                            <div class="sk-rect4"></div>
                            <div class="sk-rect5"></div>
                        </div>
                        <table class="table table-striped table-bordered table-hover dataTables-example text-center">
                            <thead>
                                <tr>
                                    <th class="text-center">序号</th>
                                    <th class="text-center">编码前缀</th>
                                    <th class="text-center">开始编号</th>
                                    <th class="text-center">结束编号</th>
                                    <th class="text-center">产码数量</th>
                                    <th class="text-center">红包金额（元）</th>
                                    <th class="text-center">产码时间</th>
                                    <th class="text-center">启用时间</th>
                                    <th class="text-center">操作</th>
                                </tr>
                            </thead>
                            <tbody>                             
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>

    $(function() {
		var table = $('.dataTables-example')
				.DataTable(
						{
							"bPaginate" : true,//翻页功能
							"bSort" : false,//排序功能
							"iDisplayLength" : 10,//每页显示的行数
							'bLengthChange' : false, //是否允许用户自定义每页显示条数。
							"bProcessing" : false, // 是否显示取数据时的那个等待提示
							"bServerSide" : true,//这个用来指明是通过服务端来取数据
							"sAjaxSource" : "./recordListFound",//这个是请求的地址
							"fnServerData" : retrieveData, // 获取数据的处理函数
							"aoColumns" : [
									{
										"sClass" : "center",
										"bSearchable" : true,
										"aTargets" : [ 0 ],
										"mRender" : function(
												data, type,
												full) {
											return full.sequenceNumber;
										}
									},
									{
										"sClass" : "center",
										"mRender" : function(
												data, type,
												full) {
											if (full.month_batch == null) {
												return '';
											} else {
												return full.month_batch;
											}
										}
									},
									{
										"sClass" : "center",
										"mRender" : function(
												data, type,
												full) {
											if (full.id_begin == null) {
												return '';
											} else {
												return full.id_begin;
											}
										}
									},
									{
										"sClass" : "center",
										"mRender" : function(
												data, type,
												full) {
											if (full.id_end == null) {
												return '';
											} else {
												return full.id_end;
											}
										}
									},
									{
										"sClass" : "center",
										"mRender" : function(
												data, type,
												full) {
											if (full.number == null) {
												return '';
											} else {
												return full.number;
											}
										}
									},
									{
										"sClass" : "center",
										"mRender" : function(
												data, type,
												full) {
											if (full.money == null) {
												return 0;
											} else {
												return full.money/100;
											}
										}
									},
									{
										"sClass" : "center",
										"mRender" : function(
												data, type,
												full) {
											if (full.create_time == null) {
												return '';
											} else {
												return full.create_time;
											}
										}
									},
									{
										"sClass" : "center",
										"mRender" : function(
												data, type,
												full) {
											if (full.valid_time == null || full.valid == 0) {
												return '';
											} else {
												return full.valid_time;
											}
										}
									},
									{
										"sClass" : "center",
										"mRender" : function(
												data, type,
												full) {
											/* if(adminView.roleId==3 || adminView.roleId==1){
												return '';
											}  */											
											if(full.valid == 1){
												return '<button class="btn btn-danger" id="changeBtn" onclick="changeValid('
												+ full.id
												+ ',0);">禁用</button>';
											}else{
												return '<button class="btn btn-primary" id="changeBtn" onclick="changeValid('
														+ full.id
														+ ',1);">启用</button>';												
											}
											
										}
									} ]
						});
	});

	//分页方法
	function retrieveData(sSource, aoData, fnCallback) {
		var dataArr = eval("[" + JSON.stringify(aoData) + "]");

		$.ajax({
			url : sSource, //这个就是请求地址对应sAjaxSource
			data : {
				"aoData" : JSON.stringify(dataArr)
			},//这个是把datatable的一些基本数据传给后台,比如起始位置,每页显示的行数
			type : 'post',
			dataType : 'json',
			async : false,
			beforeSend : function(XMLHttpRequest) {
				//alert('ss');
				$('#progressBar').show();
			},
			success : function(result) {
				fnCallback(result);//把返回的数据传给这个方法就可以了,datatable会自动绑定数据的
				$('#progressBar').hide();
			},
			error : function(msg) {
				layer.msg('数据加载失败');
			}
		});
	}
	
	function changeValid(id,valid){		
		if(valid == 0){//禁用
			setValid1(id,valid);
		}else if(valid == 1){
			setValid2(id,valid)
		}else{
			layer.msg('数据加载错误');
		}	
		
	}
	
	//删除信息
	function setValid1(id,valid) {
        swal({
            title: "您确定要禁用这条信息吗",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "禁用",
            cancelButtonText: "取消",
            closeOnConfirm: false
        }, function () {
			$.ajax({
				url:'./setValid',
				data:{'id':id,'valid':valid},
				type:'post',
				error : function(data) {
					swal("操作失败！", data.message, "error");
				},
				success : function(data) {
					if (data.state==1) {
						swal("操作成功！", "您已经禁用了这条信息", "success");
						setInterval(function(){
							location.reload();								
						}, 2000); 
					} else {
						swal("操作失败！", data.message, "error");
					}
				}
			});                
        });
    }
	
	function setValid2(id,valid){
		$.ajax({
			url:'./setValid',
			data:{'id':id,'valid':valid},
			type:'post',
			error:function(data){
				swal("操作失败！", 'connection error!', "error");
			},
			success:function(data){
				swal("操作成功！", "您已经启用了这条信息", "success");
				setInterval(function(){
					location.reload();								
				}, 2000); 
			}
		})
	}
	
    </script>
</body>
</html>
